﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class Manageweb_Users_UpdateMiYao : System.Web.UI.Page
{

    public string StrKey;

    protected override void Render(HtmlTextWriter writer)
    {
        System.IO.StringWriter sw = new System.IO.StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        base.Render(htw);

        if (!hidMiYao.Value.Equals("1"))
        {
            writer.Write(sw.ToString().Replace("<body", "<body onload=javascript:openLayer('test','test_con');"));
        }
        else
        {
            writer.Write(sw);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        StrKey = CheckData();
        if (hidMiYao.Value.Equals("1"))
        {
            this.Tab_MiYao.Visible = true;
            

        }
    }

    //获取密钥Cdefine5
    public string CheckData()
    {
        SqlParameter[] paras ={ 
                new SqlParameter("@userid",SqlDbType.VarChar,30)
            };
        paras[0].Value = Session["userid"];

        StrKey = SQLExpressDAL.SqlHelper.FillDataSet(CommandType.StoredProcedure, "UP_GetUserKey", paras).Tables[0].Rows[0][1].ToString();
        return StrKey;
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        string msg = "密钥更改成功!";

        try
        {

            SQLExpressDAL.DealRecord obj = new SQLExpressDAL.DealRecord();
            int flag = obj.UpdateUserMiYao(Session["UserID"].ToString(), this.txt_CurrMiYao.Text.Trim(), this.txt_NewMiYao.Text.Trim());

            if (flag == 0)
            {
                msg = "密钥更改失败!\\n确认原密钥是否正确!";
            }
        }
        catch (Exception ex)
        {
            msg = "密钥更改失败!";
        }

        ClientScript.RegisterStartupScript(this.GetType(), "msg", "alert('" + msg + "')", true);
    }
}
